** Preamble **
 
clear all
set more off

local path_input  "C:/Users/$user/Dropbox/$project/master/output/data"
local path_output "C:/Users/$user/Dropbox/$project/master/output/tables"

* Note: local directory is the output folder 
cd "`path_output'"


					** Loading the input file **


use `path_input'/dataset_final_may20 , clear


*estimates for RM
cap drop _merge
merge m:1 codigo_ibge using `path_input'/RegioesMetro_StateCapitals.dta

replace rm="AC" if municipio=="Rio Branco"   & uf=="AC"
replace rm="AM" if municipio=="Manaus" 		 & uf=="AM"
replace rm="DF" if 							   uf=="DF"
replace rm="MS" if municipio=="Campo Grande" & uf=="MS"
replace rm="PI" if municipio=="Teresina"     & uf=="PI"
replace rm="RO" if municipio=="Porto Velho"  & uf=="RO"
replace rm="RR" if municipio=="Boa Vista"    & uf=="RR"
replace rm="MT" if codigo_ibge==510340
replace rm="PB" if codigo_ibge==250750


gen RM=(_m==3)
drop _m

estimates clear

gen T=treatment
replace T=1 if turno==2
replace T=0 if uf=="MA"

tab treatment   if RM==1 & turno==2 
tab treatment   if RM==0 & turno==2
tab uf		    if RM==1 & turno==2 & treatment==0


												** Table 10 **

label var treatment "Globo" 
														
												 ** Panel A **
														
/*
The table reports regression estimates of the effect of Globo's edited coverage on Lula's and Collor's vote shares. Columns (1) and (2) report estimates using survey data. Globo's edited coverage of the debate was aired on the late evening of December 15th, 1989. Our survey data were collected on December 12th-15th and 16th, before and after coverage, respectively. Survey voting variables indicate 2nd-round vote intention for Lula and Collor. Columns (3) and (4) report the estimates using actual ballot data and include demographic characteristics interacted with year fixed effects as additional controls, repeating the baseline
specification of Columns (3) and (5) of Table 6 but restricting the sample to include only municipalities located in state-capital cities metropolitan areas to mimic the sampling of our survey data. Specifications in Columns (3) and (4) include metropolitan areas and time fixed effects. Heteroskedasticity-adjusted standard errors clustered at the state level for the survey data estimates and at the municipality level for the electoral estimates are reported below in brackets. Significantly different from zero at $99\% (***)$, $95\% (**)$ and $90\% (*)$ confidence level.
*/

local legend "The table reports regression estimates of the effect of Globo's edited coverage on Lula's and Collor's vote shares. Columns (1) and (2) report estimates using survey data. Globo's edited coverage of the debate was aired on the late evening of December 15th, 1989. Our survey data were collected on December 12th-15th and 16th, before and after coverage, respectively. Survey voting variables indicate 2nd-round vote intention for Lula and Collor. Columns (3) and (4) report the estimates using actual ballot data and include demographic characteristics interacted with year fixed effects as additional controls, repeating the baseline specification of Columns (3) and (5) of Table 6 but restricting the sample to include only municipalities located in state-capital cities metropolitan areas to mimic the sampling of our survey data. Specifications in Columns (3) and (4) include metropolitan areas and time fixed effects. Heteroskedasticity-adjusted standard errors clustered at the state level for the survey data estimates and at the municipality level for the electoral estimates are reported below in brackets. Significantly different from zero at $99\% (***)$, $95\% (**)$ and $90\% (*)$ confidence level."

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno if RM==1, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local N_  = e(N)         
estadd local r2_ = round(e(r2), 0.001)         
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno if RM==1, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local N_  = e(N)         
estadd local r2_ = round(e(r2), 0.001)         
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno if RM==0, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local N_  = e(N)         
estadd local r2_ = round(e(r2), 0.001)         
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno if RM==0, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local N_  = e(N)         
estadd local r2_ = round(e(r2), 0.001)         
estadd local PartiesControl "Yes"


esttab est1 est2 est3 est4 using Table_baseline_MSAs_panel_A.tex, 																				///
keep(treatment) order(treatment) 																												///
stat(N_ r2_ PartiesControl, fmt(0 2 0) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}" "\multicolumn{1}{c}{@}") 							///
label("Observations" "R-squared" "Electoral controls * Round" )) 																				///
mgroups("Metropolitan areas" "Non-metropolitan areas" , pattern(1 0 1 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span})) ///
star(* 0.10 ** 0.05 *** 0.01) 																													///
r2 b(3) replace  se(3) brac compress nonotes label  nogaps staraux nomtitles	 																///
nonotes addnotes("\begin{minipage}{.8\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )	
